@extends('layouts.default')
@section('content')

    @auth
        <form action="{{route('blog.store')}}" method="post">
            @csrf
            <div class="card">
                <div class="card-header">
                    博文发表
                </div>
                <div class="card-body">
                    <div class="form-group">
                        <label for="">博文</label>
                        <textarea class="form-control" id="box" name="content">{{old('content')}}</textarea>
                    </div>
                </div>
                <div class="card-footer text-muted">
                    <button type="submit" class="btn btn-success">发表</button>
                </div>
            </div>
        </form>
    @endauth
    <div class="card mt-4">
        <div class="card-header">
            博客列表
        </div>
        <div class="card-body">
            <table class="table">
                <thead>
                <tr>
                    <th width="100">编号</th>
                    <th>博文</th>
                    <th width="100">作者</th>
                    <th width="200">发布时间</th>
                    <th width="200">操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($blogs as $blog)
                    <tr>
                        <td scope="row">{{$blog->id}}</td>

                        <td>{{$blog -> content}}</td>
                    <td><a href="{{route('user.show',$blog->user->id)}}" class="">{{$blog->user->name}}</a></td>
                        <td>{{$blog -> created_at}}</td>
                        <td>
                            @auth
                                @can('delete',$blog)
                                    <form action="{{route('blog.destroy',$blog)}}" method="post">
                                        @method('DELETE')
                                        @csrf
                                        <button type="submit" class="btn btn-danger">删除</button>
                                    </form>
                                @endcan
                            @endauth
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
        <div class="card-footer text-muted">
            {{$blogs->links()}}
        </div>
    </div>
@endsection
